package dao;/*
@Date:2025/3/20
*/

import javabean.House;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.PropertyConfigurator;
import org.junit.Test;
import tool.Get;
import tool.MyhandleDbReflection;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import dao.VisitInterface;

import java.net.HttpURLConnection;
import java.util.Properties;

public class Dao {

    //列表
//    public static List<House> find() {
//        final List<House> list = MyhandleDbReflection.findList("select * from tb_house ", House.class);
//        return list;
//    }
    public static List<House> find() {
        try {
           // Get.getpropertiy();
            final SqlSession sqlSession = Get.getsqlSession();
            final VisitInterface getmapper = Get.getmapper(sqlSession, VisitInterface.class);
            final List<House> date = getmapper.findDate();
            return date;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //新增
//    public static int in(House hous){
//        final int update = MyhandleDbReflection.update("insert into tb_house values(?,?,?,?,?,?)",hous.getId(),
//                hous.getName(),hous.getTel(),hous.getAddress(),hous.getMoney(),hous.getState());
//        return update;
//    }
    public static int in(House hous) throws Exception {
       // Get.getpropertiy();
        final SqlSession sqlSession = Get.getsqlSession();
        final VisitInterface getmapper = Get.getmapper(sqlSession, VisitInterface.class);
        getmapper.inDate(hous);
        sqlSession.commit();
        return 0;
    }

    //更新
//    public static int Update(House hous) {
//        final int update = MyhandleDbReflection.update(
//                "UPDATE tb_house " +
//                        "SET name= ?,tel=?, address = ?, money = ?, state = ? " +
//                        "WHERE id = ?",
//                //"update tb_house set  name= ?,tel=?, address = ?, money = ?, state = ?, where id = ?",
//                hous.getName(), hous.getTel(), hous.getAddress(), hous.getMoney(), hous.getState(), hous.getId());
//        return update;
//    }
    public static int Update(House hous) throws IOException {

        int i=0;
        try {
          // Get.getpropertiy();
            final SqlSession sqlSession = Get.getsqlSession();
            final VisitInterface getmapper = Get.getmapper(sqlSession, VisitInterface.class);
            i = getmapper.updateDate(hous);
            sqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

    //查找
//    public static List<House> findone(int x) {
//        String sql = "select * from tb_house WHERE id ='" + x + "'";
//        final List<House> list = MyhandleDbReflection.findList(
//                sql, House.class
//                // "select * from tb_house WHERE id ='"+hous.getId()+"'",javabean.House.class
//        );
//        return list;
//    }
    public static List<House> findone(int x) {
        List<House> date=null;
        try {
           // Get.getpropertiy();
            final SqlSession sqlSession = Get.getsqlSession();
            final VisitInterface getmapper = Get.getmapper(sqlSession, VisitInterface.class);
            date = getmapper.findDateone(x);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }


    //删除
//    public static int del(int x) {
//        final int update = MyhandleDbReflection.update(
//                "delete from tb_house WHERE id = ?", x);
//        //"update tb_house set  name= ?,tel=?, address = ?, money = ?, state = ?, where id = ?",
//
//        return update;
//    }
    public static int del(int x) {
        try {
           // Get.getpropertiy();
            final SqlSession sqlSession = Get.getsqlSession();
            final VisitInterface getmapper = Get.getmapper(sqlSession, VisitInterface.class);
            getmapper.deleteDate(x);
            sqlSession.commit();
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }


        return 0;
    }
    //登录
    public static boolean login() throws SQLException {
        final boolean flag = MyhandleDbReflection.isAdmin();
        return flag;
    }

    //验证码
    public static String generateCode() {
        final String cap = MyhandleDbReflection.getCap();
        return cap;
    }
}
